<?php
/*
  $Id$

  osCommerce, Open Source E-Commerce Solutions
  http://www.oscommerce.com

  Copyright (c) 2010 osCommerce

  Released under the GNU General Public License
*/

//mvigil514 bof Compare Products
	$cPathCompare = $_GET['cPath'];
	$pageCompare = $_GET['page'];
	$sortCompare = $_GET['sort'];
	$mfrCompare = $_GET['manufacturers_id'];
	$filterCompare = $_GET['filter_id'];
		
	if (isset($HTTP_GET_VARS['sortby'])) { $sortby2 = (int)($HTTP_GET_VARS['sortby']);}
		 else { $sortby2 = 1; }
//mvigil514 eof Compare Products

 //-----------------Modify by NamHai 12/07/2012-----------------------
  //$listing_split = new splitPageResults($listing_sql, MAX_DISPLAY_SEARCH_RESULTS, 'p.products_id'); // constant "MAX_DISPLAY_SEARCH_RESULTS" set default ==20 in table "configuration" when install OSC
  $max_row_per_page = 6;
  $listing_split = new splitPageResults($listing_sql, $max_row_per_page, 'p.products_id'); // here set "$max_rows==2" per page (review 'class/split_page_results.php')
  
 //-----------------End by NamHai 12/07/2012---------------------------

//mvigil514 bof Compare Products
	$urlString = $_SERVER['QUERY_STRING'];
	if (substr($urlString, 0, 5) == 'manuf') {
		$compare_link = tep_href_link(FILENAME_COMPARE, ($mfrCompare ? 'manufacturers_id=' . $mfrCompare . '&page=' . $pageCompare . '&sort=' . $sortCompare . '&filter_id=' . $filterCompare : ''));
		echo tep_draw_form('compare', tep_href_link(FILENAME_COMPARE, ($mfrCompare ? 'manufacturers_id=' . $mfrCompare . '&page=' . $pageCompare . '&sort=' . $sortCompare . '&filter_id=' . $filterCompare : '')),'post','onsubmit="return validateButton();"' ,'', true);
	} else {	
		$compare_link = tep_href_link(FILENAME_COMPARE, ($cPathCompare ? 'cPath=' . $cPathCompare . '&page=' . $pageCompare . '&sort=' . $sortCompare . '&filter_id=' . $filterCompare : ''));
		echo tep_draw_form('compare', tep_href_link(FILENAME_COMPARE, ($cPathCompare ? 'cPath=' . $cPathCompare . '&page=' . $pageCompare . '&sort=' . $sortCompare . '&filter_id=' . $filterCompare : '')),'post','onsubmit="return validateButton();"' ,'', true);
	}
//mvigil514 eof Compare Products

$data_ok = ($listing_split->number_of_rows > 0);

if ((PRODUCT_LIST_DESCRIPTION ) && $data_ok) {
	$listing_query = tep_db_query($listing_split->sql_query);
	while ($products = tep_db_fetch_array($listing_query)) $id_array[] = $products['products_id'];
	
	$pid_string = implode(',', array_unique($id_array));
	$product_query = tep_db_query("select products_id, products_description from " . TABLE_PRODUCTS_DESCRIPTION . " where products_id in (" . $pid_string . ") and language_id = '" . (int)$languages_id . "'");
	while ($products = tep_db_fetch_array($product_query)) {
		$t_desc[$products['products_id']] = substr(strip_tags($products['products_description']), 0, PRODUCT_LIST_DESCRIPTION_MAX_LENGTH);
	}
}

function product_description($product_id,$link) {
	global $t_desc;
	if (PRODUCT_LIST_DESCRIPTION) {
		return '<br /><span class="productDesc">' . $t_desc[$product_id] . $link . '<strong>...' . MORE . '</strong></a></span>';
	} else {
		return false;
	}
}

?>  
  <div class="contentText">

<?php
  if ( ($listing_split->number_of_rows > 0) && ( (PREV_NEXT_BAR_LOCATION == '1') || (PREV_NEXT_BAR_LOCATION == '3') ) ) {
	//----------------------Modify and added by NamHai 12/07/2012-----------------------
        ?>
        <div>
            <span style="float: left;"><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_1); ?></span>
        </div>
        <br />
        <br />
        <?php

    //--------------------------End by NamHai 12/07/2012----------------------
  }

  $prod_list_contents = '<div class="ui-widget infoBoxContainer">' .
                        '  <div class="ui-widget-header ui-corner-top infoBoxHeading">' .
                        '    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingHeader">' .
                        '      <tr>';

  for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
    $lc_align = '';

    switch ($column_list[$col]) {
      case 'PRODUCT_LIST_MODEL':
        $lc_text = TABLE_HEADING_MODEL;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_NAME':
        $lc_text = TABLE_HEADING_PRODUCTS;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_MANUFACTURER':
        $lc_text = TABLE_HEADING_MANUFACTURER;
        $lc_align = '';
        break;
      case 'PRODUCT_LIST_PRICE':
        $lc_text = TABLE_HEADING_PRICE;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_QUANTITY':
        $lc_text = TABLE_HEADING_QUANTITY;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_WEIGHT':
        $lc_text = TABLE_HEADING_WEIGHT;
        $lc_align = 'right';
        break;
      case 'PRODUCT_LIST_IMAGE':
        $lc_text = TABLE_HEADING_IMAGE;
        $lc_align = 'center';
        break;
      case 'PRODUCT_LIST_BUY_NOW':
        $lc_text = TABLE_HEADING_OPTION;
        $lc_align = 'center';
        break;
    }

    if ( ($column_list[$col] != 'PRODUCT_LIST_BUY_NOW') && ($column_list[$col] != 'PRODUCT_LIST_IMAGE') ) {
      $lc_text = tep_create_sort_heading($HTTP_GET_VARS['sort'], $col+1, $lc_text);
    }

    $prod_list_contents .= '        <td' . (tep_not_null($lc_align) ? ' align="' . $lc_align . '"' : '') . '>' . $lc_text . '</td>';
  }

  $prod_list_contents .= '      </tr>' .
                         '    </table>' .
                         '  </div>';

  if ($listing_split->number_of_rows > 0) {
		$products_found = true;
    $rows = 0;
    $listing_query = tep_db_query($listing_split->sql_query);
		$prodCount = mysql_num_rows($listing_query);

    $prod_list_contents .= '  <div class="ui-widget-content ui-corner-bottom productListTable">' .
                           '    <table border="0" width="100%" cellspacing="0" cellpadding="2" class="productListingData">';
/*
$jstar_str='<script type="text/javascript">
            $(document).ready(function(){';
                  
$jstar_str.=' }); </script>'; */       
				
    while ($listing = tep_db_fetch_array($listing_query)) {
      $rows++;

      $prod_list_contents .= '      <tr>';

      for ($col=0, $n=sizeof($column_list); $col<$n; $col++) {
        switch ($column_list[$col]) {
          case 'PRODUCT_LIST_MODEL':
            $prod_list_contents .= '        <td>' . $listing['products_model'] . '</td>';
            break;
          case 'PRODUCT_LIST_NAME':
              //mvigil514 bof Compare Products
/*
              $prod_list_contents .= '        <td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a></td>';
            } else {
						
              $prod_list_contents .= '        <td><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a></td>';
*/

	$man_id = (tep_not_null($_GET['manufacturers_id']) ? $_GET['manufacturers_id'] : '');
	
	$link = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $listing['products_id'] . ($man_id ? '&manufacturers_id='.$man_id : ($cPath && $cat_path ? '&cPath=' . $cPath : '')) ) . '"' . ($man_id || ($cat_path && $cat_path) ? ' rel="nofollow"' : '') . '>';

	if ($prodCount > 1) {
              $prod_list_contents .= '        <td width="250">' . $link . $listing['products_name'] . '</a>' . product_description($listing['products_id'],$link) . '<br /><span><input type="checkbox" name="checkgroup[]" class="compare" id="checkgroup" value="'.$listing['products_id'].'" onClick="javascript:updateCompare();"/><a href="'.$compare_link.'" onClick="return validateButton();">' . TEXT_COMPARE_CHECKBOX . '</a></span></td>';
					} else {
              $prod_list_contents .= '        <td width="250">' . $link . $listing['products_name'] . '</a>' . product_description($listing['products_id'],$link) . '</td>';
					}
//mvigil514 eof Compare Products
            break;
          case 'PRODUCT_LIST_MANUFACTURER':
            $prod_list_contents .= '        <td><a href="' . tep_href_link(FILENAME_DEFAULT, 'manufacturers_id=' . $listing['manufacturers_id']) . '">' . $listing['manufacturers_name'] . '</a></td>';
            break;
          case 'PRODUCT_LIST_PRICE':
            if (tep_not_null($listing['specials_new_products_price'])) {
              $prod_list_contents .= '        <td align="right width="100"><del>' .  $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</del>&nbsp;&nbsp;<span class="productSpecialPrice">' . $currencies->display_price($listing['specials_new_products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></td>';
            } else {
              $prod_list_contents .= '        <td align="right" width="100"><span class="price_red">' . $currencies->display_price($listing['products_price'], tep_get_tax_rate($listing['products_tax_class_id'])) . '</span></td>';
            }
            break;
          case 'PRODUCT_LIST_QUANTITY':
            $prod_list_contents .= '        <td align="right">' . $listing['products_quantity'] . '</td>';
            break;
          case 'PRODUCT_LIST_WEIGHT':
            $prod_list_contents .= '        <td align="right">' . $listing['products_weight'] . '</td>';
            break;
          case 'PRODUCT_LIST_IMAGE':
            if (isset($HTTP_GET_VARS['manufacturers_id'])  && tep_not_null($HTTP_GET_VARS['manufacturers_id'])) {//DIR_WS_IMAGES .
              $prod_list_contents .= '   <td align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . tep_image( $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';
			  
            } else {//DIR_WS_IMAGES .
              $prod_list_contents .= '        <td><div class="product_img"><p><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, ($cPath ? 'cPath=' . $cPath . '&' : '') . 'products_id=' . $listing['products_id']) . '">' . tep_image( $listing['products_image'], $listing['products_name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></p>';
			  
		/*	 $jstar_str.='$'."('.star".$rows."').jRating({
                                type:'small',
                                isDisabled : true,
                                length : 5,
                                decimalLength : 1,
                                rateMax : 5
                     });";.reviews*/
				
		   $prod_list_contents .= '<div class="star_rating" id="'.$listing['products_rating'].'_1"></div>';
				
			$prod_list_contents .= '<span class="reviews"> ('.$listing['products_review_count'].')</span>';
			$prod_list_contents .= '</div>';
         }
            break; 
			//tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id']))
          case 'PRODUCT_LIST_BUY_NOW':     
 $prod_list_contents .= '        <td align="center">';
 
 if ($listing['products_price'] > 0 ) 
 {
 $prod_list_contents .= '<a href = "'.tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])  . '"> '.IMAGE_BUTTON_BUY_NOW.'</a> | ';
  
   $prod_list_contents .= '<a href = "'.tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=add_cart&products_id=' . $listing['products_id'])  . '"> '.IMAGE_BUTTON_IN_CART.'</a>';
}
 
 /*  $prod_list_contents .= tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])) ;
  */
 
   $prod_list_contents .= tep_draw_hidden_field('products_id', $product_info['products_id']);
 
   $prod_list_contents .='</td>';			
            break;
        }
      }

      $prod_list_contents .= '      </tr>';
    }

    $prod_list_contents .= '    </table>' .
                           '  </div>' .
                           '</div>';

    echo $prod_list_contents;
  } else {
		$products_found = false;
?>

    <p><?php echo TEXT_NO_PRODUCTS; ?></p>

<?php
  }

  if ( ($listing_split->number_of_rows > 0) && ((PREV_NEXT_BAR_LOCATION == '2') || (PREV_NEXT_BAR_LOCATION == '3')) ) { 

		//------------------------Modify and added by NamHai 12/07/2012-----------------
    		$max_number_pages_display = 4;
    	?>
        <br />
        <div>
            <span><?php echo $listing_split->display_count(TEXT_DISPLAY_NUMBER_OF_PRODUCTS_1); ?></span>
            <span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' .$listing_split->display_pages_result($max_number_pages_display, tep_get_all_get_params(array('page', 'info', 'x', 'y')), $max_row_per_page); ?></span>
            
            <!--<span style="float: right;"><?php echo TEXT_RESULT_PAGE . ' ' . $listing_split->display_pages_result(MAX_DISPLAY_PAGE_LINKS, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span>-->
            <center><span><?php echo $listing_split->display_links_filter($max_number_pages_display, tep_get_all_get_params(array('page', 'info', 'x', 'y'))); ?></span></center>
        </div>
        <?php
        //--------------------------End by NamHai 12/07/2012------------------------------
  	}
?>

  </div>
<?php
//mvigil514 bof Compare Products
/*
	if ($prodCount > 1) {
?>
<div style="position:absolute; top:10px; right:150px;" id="compare_button"><?php echo tep_draw_button(IMAGE_BUTTON_COMPARE, 'triangle-1-e'); ?></div>
<div style="position:absolute; top:10px; right:0px;" id="compare_button_clear"><?php echo tep_draw_button(IMAGE_BUTTON_COMPARE_CLEAR, 'triangle-1-e', '','', array('type'=>'button')); ?></div>
<?php
	}
	//mvigil514 eof Compare Products
*/	
?>
